import { getPersonList } from '@/api/person'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const usePersonStore = defineStore('personStore', () => {
  const personList = ref<[]>([])
  const JzStatistics = ref({})

  async function getPersons () {
    const { data } = await getPersonList({
      pageSize: -1,
    })
    personList.value = data.records
    JzStatistics.value = {}
    data.records.forEach((item) => {
      if (JzStatistics.value[item.jzNo]) {
        JzStatistics.value[item.jzNo].push(item);
      } else {
        JzStatistics.value[item.jzNo] = [item]
      }
    })
  }

  return { JzStatistics, personList, getPersons }
})
